﻿using Mvc2Ng.Web.UI.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Mvc2Ng.Web.UI.Code {
  public class Api : Controller {

    protected override JsonResult Json(object data, string contentType, System.Text.Encoding contentEncoding, JsonRequestBehavior behavior) {
      return new JsonDotNetResult {
        Data = data,
        ContentType = contentType,
        ContentEncoding = contentEncoding,
        JsonRequestBehavior = behavior
      };
    }

    protected JsonResult JsonList<T>(IEnumerable<T> data, int max, JsonRequestBehavior behavior)
    where T : EaBase {
      return new JsonDotNetResult {
        Data = new {
          data = data.Take(max).AsEnumerable(),
          total = data.Count(),
          max = max
        },
        ContentType = "application/json",
        ContentEncoding = System.Text.Encoding.UTF8,
        JsonRequestBehavior = behavior
      };
    }


  }
}